Imports System.Diagnostics.Process
Imports System.Threading
Public Class F_Activities
    Dim WithEvents SBO_Application As SAPbouiCOM.Application
    Dim Ocompany As SAPbobsCOM.Company
    Sub New(ByVal ocompany1 As SAPbobsCOM.Company, ByVal sbo_application1 As SAPbouiCOM.Application)
        SBO_Application = sbo_application1
        Ocompany = ocompany1
    End Sub
    Public Sub Activities_bind(ByVal oform As SAPbouiCOM.Form)
        Try

            CFL_BP_PetMaster(oform, SBO_Application)
            'CFL_BP_Employee_Mobile(oform, SBO_Application)
            oCombo = oform.Items.Item("21").Specific
            ComboLoad_Actvities(oform, oCombo)
            oCombo = oform.Items.Item("33").Specific
            ComboLoad_Program(oform, oCombo)
            oEdit = oform.Items.Item("6").Specific
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oEdit = oform.Items.Item("17").Specific
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oEdit = oform.Items.Item("8").Specific
            oEdit.String = "Open"
            oEdit = oform.Items.Item("13").Specific
            oEdit.ChooseFromListUID = "CFLPM"
            oEdit.ChooseFromListAlias = "U_PetCode"
            'oEdit = oform.Items.Item("ACT1000004").Specific
            'oEdit.ChooseFromListUID = "CFLEMPM"
            'oEdit.ChooseFromListAlias = "U_AI_MobileUser"
            oform.DataBrowser.BrowseBy = "4"
        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try

    End Sub
    Public Sub Activities_bind_TraingEvl(ByVal oform As SAPbouiCOM.Form)
        Try

            CFL_BP_PetMaster(oform, SBO_Application)
            oCombo = oform.Items.Item("19").Specific
            oCombo.ValidValues.Add("TAgility", "Training -  Agility")
            oCombo.ValidValues.Add("TObedien", "Training -  Obedience")
            oCombo.Select(1, SAPbouiCOM.BoSearchKey.psk_Index)
            oEdit = oform.Items.Item("6").Specific
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oEdit = oform.Items.Item("15").Specific
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oEdit = oform.Items.Item("11").Specific
            oEdit.ChooseFromListUID = "CFLPM"
            oEdit.ChooseFromListAlias = "U_PetCode"
            oform.DataBrowser.BrowseBy = "4"
        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try

    End Sub
    Public Sub Activities_bind_Prog(ByVal oform As SAPbouiCOM.Form)
        Try
            CFL_BP_PetMaster(oform, SBO_Application)
            CFL_BP_PetMaster1(oform, SBO_Application)
            oform.DataSources.UserDataSources.Add("oedit1", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit2", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit3", SAPbouiCOM.BoDataType.dt_DATE)
            oform.DataSources.UserDataSources.Add("oedit4", SAPbouiCOM.BoDataType.dt_DATE)
            oEdit = oform.Items.Item("4").Specific
            oEdit.DataBind.SetBound(True, "", "oedit1")
            oEdit.ChooseFromListUID = "CFLPM"
            oEdit.ChooseFromListAlias = "U_PetCode"
            oEdit = oform.Items.Item("6").Specific
            oEdit.DataBind.SetBound(True, "", "oedit2")
            oEdit.ChooseFromListUID = "CFLPM1"
            oEdit.ChooseFromListAlias = "U_PetCode"
            oEdit = oform.Items.Item("8").Specific
            oEdit.DataBind.SetBound(True, "", "oedit3")
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oEdit = oform.Items.Item("10").Specific
            oEdit.DataBind.SetBound(True, "", "oedit4")
            oEdit.String = Format(Now.Date, "dd/MM/yy")

        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try

    End Sub
    Public Sub Activities_bind_Act(ByVal oform As SAPbouiCOM.Form)
        Try
            CFL_BP_PetMaster(oform, SBO_Application)
            oform.DataSources.UserDataSources.Add("oedit1", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit2", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit3", SAPbouiCOM.BoDataType.dt_DATE)
            oform.DataSources.UserDataSources.Add("oedit4", SAPbouiCOM.BoDataType.dt_DATE)
            oform.DataSources.UserDataSources.Add("oedit5", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit6", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("oedit7", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("V_0", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("V_1", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oform.DataSources.UserDataSources.Add("V_2", SAPbouiCOM.BoDataType.dt_SHORT_TEXT)
            oEdit = oform.Items.Item("4").Specific
            oEdit.DataBind.SetBound(True, "", "oedit1")
            oEdit.ChooseFromListUID = "CFLPM"
            oEdit.ChooseFromListAlias = "U_PetCode"
            oEdit = oform.Items.Item("8").Specific
            oEdit.DataBind.SetBound(True, "", "oedit3")
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oEdit = oform.Items.Item("10").Specific
            oEdit.DataBind.SetBound(True, "", "oedit4")
            oEdit.String = Format(Now.Date, "dd/MM/yy")
            oMatrix = oform.Items.Item("1000001").Specific
            oColumns = oMatrix.Columns
            oColumn = oColumns.Item("V_0")
            oColumn.DataBind.SetBound(True, "", "V_0")
            oColumn = oColumns.Item("V_1")
            oColumn.DataBind.SetBound(True, "", "V_1")
            oColumn = oColumns.Item("V_2")
            oColumn.DataBind.SetBound(True, "", "V_2")

            MatrixLoad()

        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try

    End Sub
    Private Sub MatrixLoad()
        Dim sqlstr As String = "SELECT T0.[Code], T0.[Name],'Y' as 'Y' FROM [dbo].[@AI_PROGRAM]  T0 WHERE T0.[U_AI_ForGrouping] ='Y' ORDER BY cast(T0.[U_AI_GroupSeqNo] as int)"
        oForm.DataSources.DataTables.Add("OWHS")
        oForm.DataSources.DataTables.Item("OWHS").ExecuteQuery(sqlstr)
        oMatrix = oForm.Items.Item("1000001").Specific
        oMatrix.Clear()
        oMatrix.SelectionMode = SAPbouiCOM.BoMatrixSelect.ms_None
        oColumns = oMatrix.Columns
        oForm.Items.Item("1000001").Specific.Columns.item("V_1").DataBind.Bind("OWHS", "Code")
        oForm.Items.Item("1000001").Specific.Columns.item("V_0").DataBind.Bind("OWHS", "Name")
        oForm.Items.Item("1000001").Specific.Columns.item("V_2").DataBind.Bind("OWHS", "Y")
        oForm.Items.Item("1000001").Specific.Clear()
        oForm.Items.Item("1000001").Specific.LoadFromDataSource()
        oForm.Items.Item("1000001").Specific.AutoResizeColumns()

    End Sub
    Private Sub ComboLoad_Program(ByRef Oform As SAPbouiCOM.Form, ByRef oCombo As SAPbouiCOM.ComboBox)
        Try
            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            oRecordSet.DoQuery("SELECT T0.Code, T0.Name FROM [dbo].[@AI_PROGRAM]  T0 ORDER BY T0.[Code]")
            Dim it As Integer = 1
            For it = oCombo.ValidValues.Count - 1 To 0 Step -1
                oCombo.ValidValues.Remove(it, SAPbouiCOM.BoSearchKey.psk_Index)
            Next
            Do While Not oRecordSet.EoF
                oCombo.ValidValues.Add(oRecordSet.Fields.Item(0).Value, oRecordSet.Fields.Item(1).Value)
                oRecordSet.MoveNext()
            Loop
            'If oRecordSet.RecordCount > 0 Then
            '    oRecordSet.MoveFirst()
            '    oCombo.Select(oRecordSet.Fields.Item(0).Value, SAPbouiCOM.BoSearchKey.psk_ByValue)
            'End If
            oRecordSet = Nothing
            GC.Collect()
        Catch ex As Exception
            'SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try
    End Sub
    Private Sub ComboLoad_Level(ByRef Oform As SAPbouiCOM.Form, ByRef oCombo As SAPbouiCOM.ComboBox, ByVal Level As String)
        Try
            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            oRecordSet.DoQuery("SELECT T0.[Code], T0.[Name] FROM [dbo].[@AI_TRAINING_LEVER]  T0 WHERE T0.[U_TType] = '" & Level & "'")
            Dim it As Integer = 1
            For it = oCombo.ValidValues.Count - 1 To 0 Step -1
                oCombo.ValidValues.Remove(it, SAPbouiCOM.BoSearchKey.psk_Index)
            Next
            Do While Not oRecordSet.EoF
                oCombo.ValidValues.Add(oRecordSet.Fields.Item(0).Value, oRecordSet.Fields.Item(1).Value)
                oRecordSet.MoveNext()
            Loop
            'If oRecordSet.RecordCount > 0 Then
            '    oRecordSet.MoveFirst()
            '    oCombo.Select(oRecordSet.Fields.Item(0).Value, SAPbouiCOM.BoSearchKey.psk_ByValue)
            'End If
            oRecordSet = Nothing
            GC.Collect()
        Catch ex As Exception
            'SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try
    End Sub
    Private Sub ComboLoad_Training(ByRef Oform As SAPbouiCOM.Form, ByRef oCombo As SAPbouiCOM.ComboBox, ByVal Level As String, ByVal Type As String)
        Try
            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            oRecordSet.DoQuery("SELECT T0.Code, T0.Name, T0.U_TType, T0.U_TLevel FROM [dbo].[@AI_TRAININGSUBLEVEL]  T0 WHERE T0.[U_TType] ='" & Type & "' and  T0.[U_TLevel] ='" & Level & "'")
            Dim it As Integer = 1
            For it = oCombo.ValidValues.Count - 1 To 0 Step -1
                oCombo.ValidValues.Remove(it, SAPbouiCOM.BoSearchKey.psk_Index)
            Next
            Do While Not oRecordSet.EoF
                oCombo.ValidValues.Add(oRecordSet.Fields.Item(0).Value, oRecordSet.Fields.Item(1).Value)
                oRecordSet.MoveNext()
            Loop
            'If oRecordSet.RecordCount > 0 Then
            '    oRecordSet.MoveFirst()
            '    oCombo.Select(oRecordSet.Fields.Item(0).Value, SAPbouiCOM.BoSearchKey.psk_ByValue)
            'End If
            oRecordSet = Nothing
            GC.Collect()
        Catch ex As Exception
            'SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try
    End Sub
    Private Sub ComboLoad_Actvities(ByRef Oform As SAPbouiCOM.Form, ByRef oCombo As SAPbouiCOM.ComboBox)
        Try
            oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            oRecordSet.DoQuery("SELECT T0.[Code], T0.[Name] FROM [dbo].[@AI_PROGRAM]  T0 WHERE T0.[U_AI_ForGrouping] ='Y'")
            Dim it As Integer = 1
            For it = oCombo.ValidValues.Count - 1 To 0 Step -1
                oCombo.ValidValues.Remove(it, SAPbouiCOM.BoSearchKey.psk_Index)
            Next
            Do While Not oRecordSet.EoF
                oCombo.ValidValues.Add(oRecordSet.Fields.Item(0).Value, oRecordSet.Fields.Item(1).Value)
                oRecordSet.MoveNext()
            Loop
            oRecordSet = Nothing
            GC.Collect()
        Catch ex As Exception
            SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try
    End Sub

    Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent

        Try

            If pVal.FormUID = "ActivitiesReport" And pVal.ItemUID = "1000002" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then

                Dim J As Integer = 0
                '  Dim WhscSQLCode As String = ""
                For J = 1 To oMatrix.RowCount
                    oCheck = oMatrix.Columns.Item("V_2").Cells.Item(J).Specific
                    oCheck.Checked = True
                Next

            End If
            If pVal.FormUID = "ActivitiesReport" And pVal.ItemUID = "Print" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                'ActivitiesReport()
                Dim trd As Threading.Thread
                trd = New Threading.Thread(AddressOf ActivitiesReport)
                trd.IsBackground = True
                trd.SetApartmentState(ApartmentState.STA)
                trd.Start()
            End If

            '----------------
            If pVal.FormUID = "ActivitiesReport" Then
                oForm = SBO_Application.Forms.Item("ActivitiesReport")
                If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST Then
                    Dim oCFLEvento As SAPbouiCOM.IChooseFromListEvent
                    oCFLEvento = pVal
                    Dim sCFL_ID As String
                    sCFL_ID = oCFLEvento.ChooseFromListUID
                    oForm = SBO_Application.Forms.Item(FormUID)
                    Dim oCFL As SAPbouiCOM.ChooseFromList
                    oCFL = oForm.ChooseFromLists.Item(sCFL_ID)
                    Try
                        If oCFLEvento.BeforeAction = False Then
                            Dim oDataTable As SAPbouiCOM.DataTable
                            oDataTable = oCFLEvento.SelectedObjects
                            If pVal.ItemUID = "4" Then

                                Try
                                    oEdit = oForm.Items.Item("4").Specific
                                    oEdit.String = oDataTable.GetValue("U_PetCode", 0)
                                Catch ex As Exception
                                End Try
                            End If
                            If pVal.ItemUID = "6" Then
                                'oEdit = oForm.Items.Item("26").Specific
                                'oEdit.String = oDataTable.GetValue("U_U_PetName", 0)
                                Try
                                    oEdit = oForm.Items.Item("6").Specific
                                    oEdit.String = oDataTable.GetValue("U_PetCode", 0)
                                Catch ex As Exception
                                End Try

                            End If
                        End If
                    Catch ex As Exception
                        '' SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                    End Try
                End If
            End If
            '--------------------


            If pVal.FormUID = "ProgressReport" And pVal.ItemUID = "Print" And pVal.Before_Action = True And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
                oForm = SBO_Application.Forms.Item("ProgressReport")
                Dim Sqlstr As String = ""
                Dim FPet As String = ""
                Dim TPet As String = ""
                Dim FDt As String = ""
                Dim TDt As String = ""
                oEdit = oForm.Items.Item("4").Specific
                If oEdit.String = "" Then
                    SBO_Application.StatusBar.SetText("Plz Enter From Pet Code", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                    BubbleEvent = False
                    Exit Sub
                End If
                FPet = oEdit.String
                oEdit = oForm.Items.Item("6").Specific
                If oEdit.String = "" Then
                    SBO_Application.StatusBar.SetText("Plz Enter To Pet Code", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                    BubbleEvent = False
                    Exit Sub
                End If
                TPet = oEdit.String
                oEdit = oForm.Items.Item("8").Specific
                If oEdit.String = "" Then
                    SBO_Application.StatusBar.SetText("Plz Enter From Date", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                    BubbleEvent = False
                    Exit Sub
                End If
                FDt = oEdit.Value
                oEdit = oForm.Items.Item("10").Specific
                If oEdit.String = "" Then
                    SBO_Application.StatusBar.SetText("Plz Enter To Date", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                    BubbleEvent = False
                    Exit Sub
                End If
                TDt = oEdit.Value

                Try
                    SBO_Application.StatusBar.SetText("Retrieving Data", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
                    Sqlstr = "SELECT T0.[U_AI_PetCode], T0.[U_AI_PetName], T0.[U_AI_Date], T0.[U_AI_ProgCode], T0.[U_AI_ProgName], T0.[U_AI_Handler], T0.[U_AI_Progress], T0.[U_AI_Comments] FROM [dbo].[@AI_ACTIVITY]  T0 WHERE T0.[U_AI_PetCode]  between  '" & FPet & "' and  '" & TPet & "'  and  T0.[U_AI_Date]  between '" & FDt & "' and '" & TDt & "' ORDER BY T0.[U_AI_PetCode], T0.[U_AI_PetName], T0.[U_AI_Date]"
                    Dim frm As MY_Report
                    frm = New MY_Report
                    frm.Prog_Report(Sqlstr, Ocompany)
                    frm.Text = "Progress Sheet Report"
                    frm.TopMost = True
                    frm.Activate()
                    frm.ShowDialog()

                Catch ex As Exception
                End Try


            End If
            '----------------
            If pVal.FormUID = "ProgressReport" Then
                oForm = SBO_Application.Forms.Item("ProgressReport")
                If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST Then
                    Dim oCFLEvento As SAPbouiCOM.IChooseFromListEvent
                    oCFLEvento = pVal
                    Dim sCFL_ID As String
                    sCFL_ID = oCFLEvento.ChooseFromListUID
                    oForm = SBO_Application.Forms.Item(FormUID)
                    Dim oCFL As SAPbouiCOM.ChooseFromList
                    oCFL = oForm.ChooseFromLists.Item(sCFL_ID)
                    Try
                        If oCFLEvento.BeforeAction = False Then
                            Dim oDataTable As SAPbouiCOM.DataTable
                            oDataTable = oCFLEvento.SelectedObjects
                            If pVal.ItemUID = "4" Then

                                Try
                                    oEdit = oForm.Items.Item("4").Specific
                                    oEdit.String = oDataTable.GetValue("U_PetCode", 0)
                                Catch ex As Exception
                                End Try
                            End If
                            If pVal.ItemUID = "6" Then
                                'oEdit = oForm.Items.Item("26").Specific
                                'oEdit.String = oDataTable.GetValue("U_U_PetName", 0)
                                Try
                                    oEdit = oForm.Items.Item("6").Specific
                                    oEdit.String = oDataTable.GetValue("U_PetCode", 0)
                                Catch ex As Exception
                                End Try

                            End If
                        End If
                    Catch ex As Exception
                        '' SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                    End Try
                End If
            End If
            '--------------------

            'Choose From List
            If pVal.FormUID = "AI_Training" Then
                oForm = SBO_Application.Forms.Item("AI_Training")
                If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST Then
                    Dim oCFLEvento As SAPbouiCOM.IChooseFromListEvent
                    oCFLEvento = pVal
                    Dim sCFL_ID As String
                    sCFL_ID = oCFLEvento.ChooseFromListUID
                    oForm = SBO_Application.Forms.Item(FormUID)
                    Dim oCFL As SAPbouiCOM.ChooseFromList
                    oCFL = oForm.ChooseFromLists.Item(sCFL_ID)
                    Try
                        If oCFLEvento.BeforeAction = False Then
                            Dim oDataTable As SAPbouiCOM.DataTable
                            oDataTable = oCFLEvento.SelectedObjects
                            If pVal.ItemUID = "11" Then
                                oEdit = oForm.Items.Item("13").Specific
                                oEdit.String = oDataTable.GetValue("U_PetName", 0)
                                Try
                                    oEdit = oForm.Items.Item("11").Specific
                                    oEdit.String = oDataTable.GetValue("U_PetCode", 0)
                                Catch ex As Exception
                                End Try
                            End If
                        End If
                    Catch ex As Exception
                        '' SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                    End Try
                End If
            End If
            '--------------------
        Catch ex As Exception
        End Try
        '======================================================

        Try
            '------------------------------------

            'Choose From List
            If pVal.FormUID = "AI_Training" Then
                oForm = SBO_Application.Forms.Item("AI_Training")
                If pVal.EventType = SAPbouiCOM.BoEventTypes.et_COMBO_SELECT And pVal.Before_Action = False And pVal.InnerEvent = False And pVal.ItemUID = "19" Then

                    oCombo = oForm.Items.Item("19").Specific

                    If oCombo.Selected.Value = "TAgility" Then
                        oCombo = oForm.Items.Item("21").Specific
                        ComboLoad_Level(oForm, oCombo, "Agility")
                        'puni
                    ElseIf oCombo.Selected.Value = "TObedien" Then
                        oCombo = oForm.Items.Item("21").Specific
                        ComboLoad_Level(oForm, oCombo, "Obedi")
                    Else
                        oCombo = oForm.Items.Item("21").Specific
                        ComboLoad_Level(oForm, oCombo, "")
                    End If

                End If
            End If
            '----Start CFL-------------
            If pVal.FormUID = "AI_ACTIVITY" Then
                If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST Then
                    Dim oCFLEvento As SAPbouiCOM.IChooseFromListEvent
                    oCFLEvento = pVal
                    Dim sCFL_ID As String
                    sCFL_ID = oCFLEvento.ChooseFromListUID
                    oForm = SBO_Application.Forms.Item(FormUID)
                    Dim oCFL As SAPbouiCOM.ChooseFromList
                    oCFL = oForm.ChooseFromLists.Item(sCFL_ID)
                    Try
                        If oCFLEvento.BeforeAction = False Then
                            Dim oDataTable As SAPbouiCOM.DataTable
                            oDataTable = oCFLEvento.SelectedObjects
                            If pVal.ItemUID = "13" Then
                                oEdit = oForm.Items.Item("15").Specific
                                oEdit.String = oDataTable.GetValue("U_PetName", 0)
                                Try
                                    oEdit = oForm.Items.Item("13").Specific
                                    oEdit.String = oDataTable.GetValue("U_PetCode", 0)
                                Catch ex As Exception
                                End Try
                            End If
                            If pVal.ItemUID = "ACT1000004" Then
                                'oEdit = oForm.Items.Item("26").Specific
                                'oEdit.String = oDataTable.GetValue("U_U_PetName", 0)
                                Try
                                    oEdit = oForm.Items.Item("ACT31").Specific
                                    oEdit.String = oDataTable.GetValue("firstName", 0)
                                    oEdit = oForm.Items.Item("ACT1000004").Specific
                                    oEdit.String = oDataTable.GetValue("U_AI_MobileUser", 0)
                                Catch ex As Exception
                                End Try

                            End If
                        End If
                    Catch ex As Exception
                        '' SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                    End Try
                End If
            End If
            '--------------------
        Catch ex As Exception
        End Try
        '======================================================

        Try
            '-------------------End Choose From List-----------
            If pVal.FormUID = "AI_ACTIVITY" And pVal.InnerEvent = False Then
                oForm = SBO_Application.Forms.Item("AI_ACTIVITY")
                If pVal.Before_Action = False Then
                    Select Case pVal.EventType
                        Case SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED
                            If pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Then
                                If pVal.ItemUID = "1" Then
                                    oEdit = oForm.Items.Item("6").Specific
                                    oEdit.String = Format(Now.Date, "dd/MM/yy")
                                    oEdit = oForm.Items.Item("17").Specific
                                    oEdit.String = Format(Now.Date, "dd/MM/yy")
                                    oEdit = oForm.Items.Item("8").Specific
                                    oEdit.String = "Open"
                                End If
                            End If
                            'If pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Or pVal.FormMode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE Then
                            If pVal.ItemUID = "34" Then
                                oEdit = oForm.Items.Item("19").Specific
                                oEdit.String = Now.Hour.ToString() & ":" & Now.Minute.ToString()
                            End If
                            If pVal.ItemUID = "35" Then
                                oEdit = oForm.Items.Item("23").Specific
                                oEdit.String = Now.Hour.ToString() & ":" & Now.Minute.ToString()
                            End If

                            'End If
                        Case SAPbouiCOM.BoEventTypes.et_COMBO_SELECT
                            If pVal.ItemUID = "21" Then
                                oCombo = oForm.Items.Item("21").Specific
                                oEdit = oForm.Items.Item("11").Specific
                                oEdit.String = oCombo.Selected.Description

                                If oCombo.Selected.Value = "TAgility" Then
                                    oCombo = oForm.Items.Item("37").Specific
                                    ComboLoad_Level(oForm, oCombo, "Agility")
                                    'puni
                                ElseIf oCombo.Selected.Value = "TObedien" Then
                                    oCombo = oForm.Items.Item("37").Specific
                                    ComboLoad_Level(oForm, oCombo, "Obedi")
                                Else
                                    oCombo = oForm.Items.Item("37").Specific
                                    ComboLoad_Level(oForm, oCombo, "")
                                End If
                            End If
                            'ComboLoad_Training
                            If pVal.ItemUID = "37" Then
                                oCombo = oForm.Items.Item("21").Specific
                                Dim Type As String = ""
                                If oCombo.Selected.Value = "TAgility" Then
                                    Type = "Agility"
                                    'puni
                                ElseIf oCombo.Selected.Value = "TObedien" Then
                                    Type = "Obedi"
                                Else
                                    Type = ""
                                End If
                                oCombo = oForm.Items.Item("37").Specific
                                Dim Level As String = ""
                                Level = oCombo.Selected.Value
                                oCombo = oForm.Items.Item("39").Specific
                                ComboLoad_Training(oForm, oCombo, Level, Type)
                            End If
                        Case SAPbouiCOM.BoEventTypes.et_VALIDATE
                            If pVal.ItemUID = "ACT1000004" Then
                                oEdit = oForm.Items.Item("ACT1000004").Specific
                                If oEdit.String <> "" Then
                                    Dim Uname As String = MobileUserName(oEdit.String, Ocompany)
                                    oEdit = oForm.Items.Item("ACT31").Specific
                                    oEdit.String = Uname
                                End If
                            End If
                            If pVal.ItemUID = "41" Then
                                oEdit = oForm.Items.Item("41").Specific
                                Try
                                    Dim POINT As Integer
                                    POINT = oEdit.Value
                                    If POINT >= 1 And POINT <= 3 Then
                                        oCombo = oForm.Items.Item("33").Specific
                                        oCombo.Select("04", SAPbouiCOM.BoSearchKey.psk_ByValue)
                                    ElseIf POINT >= 4 And POINT <= 5 Then
                                        oCombo = oForm.Items.Item("33").Specific
                                        oCombo.Select("03", SAPbouiCOM.BoSearchKey.psk_ByValue)
                                    ElseIf POINT >= 6 And POINT <= 7 Then
                                        oCombo = oForm.Items.Item("33").Specific
                                        oCombo.Select("02", SAPbouiCOM.BoSearchKey.psk_ByValue)
                                    ElseIf POINT >= 8 Then
                                        oCombo = oForm.Items.Item("33").Specific
                                        oCombo.Select("01", SAPbouiCOM.BoSearchKey.psk_ByValue)
                                    End If
                                Catch ex As Exception

                                End Try

                            End If
                            If pVal.ItemUID = "19" Then
                                oEdit = oForm.Items.Item("19").Specific
                                If IsDate(oEdit.String) = False And oEdit.String <> "" Then
                                    SBO_Application.StatusBar.SetText("Check In Not Valid Time, Plz Enter Hour:Min Time Formate", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                    oEdit.Active = True
                                    BubbleEvent = False
                                    Exit Sub
                                End If
                            End If
                            If pVal.ItemUID = "23" Then
                                oEdit = oForm.Items.Item("23").Specific
                                If IsDate(oEdit.String) = False And oEdit.String <> "" Then
                                    SBO_Application.StatusBar.SetText("Check Out Not Valid Time, Plz Enter Hour:Min Time Formate", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                    oEdit.Active = True
                                    BubbleEvent = False
                                    Exit Sub
                                End If
                            End If

                    End Select
                ElseIf pVal.Before_Action = True Then
                    Select Case pVal.EventType
                        Case SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED
                            If pVal.FormMode = SAPbouiCOM.BoFormMode.fm_UPDATE_MODE Or pVal.FormMode = SAPbouiCOM.BoFormMode.fm_ADD_MODE Then
                                'If pVal.ItemUID = "34" Then
                                '    oEdit = oForm.Items.Item("19").Specific
                                '    oEdit.String = Now.Hour.ToString() & ":" & Now.Minute.ToString()
                                'End If
                                'If pVal.ItemUID = "35" Then
                                '    oEdit = oForm.Items.Item("23").Specific
                                '    oEdit.String = Now.Hour.ToString() & ":" & Now.Minute.ToString()
                                'End If

                                If pVal.ItemUID = "1" Then
                                    oEdit = oForm.Items.Item("11").Specific
                                    If oEdit.String = "" Then
                                        SBO_Application.StatusBar.SetText("Select Program/Activities Name", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        BubbleEvent = False
                                        Exit Sub
                                    End If
                                    oEdit = oForm.Items.Item("13").Specific
                                    If oEdit.String = "" Then
                                        SBO_Application.StatusBar.SetText("Select Pet Code", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        BubbleEvent = False
                                        Exit Sub
                                    End If
                                    oEdit = oForm.Items.Item("17").Specific
                                    If oEdit.String = "" Then
                                        SBO_Application.StatusBar.SetText("Select Activity Date", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        BubbleEvent = False
                                        Exit Sub
                                    End If
                                    oEdit = oForm.Items.Item("6").Specific
                                    If oEdit.String = "" Then
                                        SBO_Application.StatusBar.SetText("Select Document Date", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        BubbleEvent = False
                                        Exit Sub
                                    End If
                                    oEdit = oForm.Items.Item("ACT1000004").Specific
                                    If oEdit.String = "" Then
                                        SBO_Application.StatusBar.SetText("Select Handler/Trainier Code", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        BubbleEvent = False
                                        Exit Sub
                                    End If
                                    Try
                                        oCombo = oForm.Items.Item("21").Specific
                                        If oCombo.Selected.Value = "" Then
                                            SBO_Application.StatusBar.SetText("Select Program/Activities Code", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                            BubbleEvent = False
                                            Exit Sub
                                        End If

                                    Catch ex As Exception
                                        SBO_Application.StatusBar.SetText("Select Program/Activities Code", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        BubbleEvent = False
                                        Exit Sub
                                    End Try
                                    Try
                                        oCombo = oForm.Items.Item("1000002").Specific
                                        If oCombo.Selected.Value = "" Then
                                            SBO_Application.StatusBar.SetText("Select Pet/Dog Activity Status", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                            BubbleEvent = False
                                            Exit Sub
                                        End If

                                    Catch ex As Exception
                                        SBO_Application.StatusBar.SetText("Select Pet/Dog Activity Status", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        BubbleEvent = False
                                        Exit Sub
                                    End Try
                                    oEdit = oForm.Items.Item("19").Specific
                                    If IsDate(oEdit.String) = False And oEdit.String <> "" Then
                                        SBO_Application.StatusBar.SetText("Check In Time Not Valid Time, Plz Enter Hour:Min Time Formate", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        oEdit.Active = True
                                        BubbleEvent = False
                                        Exit Sub
                                    End If
                                    oEdit = oForm.Items.Item("23").Specific
                                    If IsDate(oEdit.String) = False And oEdit.String <> "" Then
                                        SBO_Application.StatusBar.SetText("Check Out Time Not Valid Time, Plz Enter Hour:Min Time Formate", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
                                        oEdit.Active = True
                                        BubbleEvent = False
                                        Exit Sub
                                    End If
                                    Try
                                        oRecordSet = Ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                                        oCombo = oForm.Items.Item("21").Specific
                                        oEdit = oForm.Items.Item("13").Specific
                                        Dim PetCode As String = oEdit.String
                                        oEdit = oForm.Items.Item("17").Specific
                                        Dim Dt As String = oEdit.Value
                                        If oCombo.Selected.Value = "Lunch" Then
                                            oRecordSet.DoQuery("update [@AI_ATTENDANCE] set U_AI_Lunch_S ='Y' where U_AI_PetCode='" & PetCode & "' and U_AI_Date='" & Dt & "'")
                                        ElseIf oCombo.Selected.Value = "Swim" Then
                                            oRecordSet.DoQuery("update [@AI_ATTENDANCE] set U_AI_Swim_S ='Y' where U_AI_PetCode='" & PetCode & "' and U_AI_Date='" & Dt & "'")
                                        ElseIf oCombo.Selected.Value = "Walk" Then
                                            oRecordSet.DoQuery("update [@AI_ATTENDANCE] set U_AI_Walk_S ='Y' where U_AI_PetCode='" & PetCode & "' and U_AI_Date='" & Dt & "'")
                                        ElseIf oCombo.Selected.Value = "Training" Then
                                            oRecordSet.DoQuery("update [@AI_ATTENDANCE] set U_AI_Training_S ='Y' where U_AI_PetCode='" & PetCode & "' and U_AI_Date='" & Dt & "'")
                                        ElseIf oCombo.Selected.Value = "Medi" Then
                                            oRecordSet.DoQuery("update [@AI_ATTENDANCE] set U_AI_Medication_S ='Y' where U_AI_PetCode='" & PetCode & "' and U_AI_Date='" & Dt & "'")
                                        End If


                                    Catch ex As Exception

                                    End Try

                                End If
                            End If
                    End Select
                End If
            End If
        Catch ex As Exception
            'SBO_Application.StatusBar.SetText(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        End Try

    End Sub
    Public Sub ActivitiesReport()
        oForm = SBO_Application.Forms.Item("ActivitiesReport")
        Dim Sqlstr As String = ""
        Dim FPet As String = ""
        Dim TPet As String = ""
        Dim FDt As String = ""
        Dim TDt As String = ""
        Dim FProg As String = ""
        Dim TProg As String = ""
        Dim St As String = ""
        oEdit = oForm.Items.Item("4").Specific
        If oEdit.String = "" Then
            FPet = "%"
        Else
            FPet = oEdit.String
        End If


        oEdit = oForm.Items.Item("8").Specific
        Dim yr As String
        If oEdit.String = "" Then
            yr = "2000"
            FDt = yr & "-01-01"
        Else
            FDt = oEdit.Value
        End If

        oEdit = oForm.Items.Item("10").Specific
        If oEdit.String = "" Then
            yr = Now.Year.ToString
            TDt = yr & "-12-31"
        Else
            TDt = oEdit.Value
        End If
        'FProg
        Dim J As Integer
        For J = 1 To oMatrix.RowCount
            oCheck = oMatrix.Columns.Item("V_2").Cells.Item(J).Specific
            If oCheck.Checked = True Then
                oEdit = oMatrix.Columns.Item("V_1").Cells.Item(J).Specific
                If FProg = "" Then
                    FProg = "'" & oEdit.String & "'"
                Else
                    FProg = "'" & oEdit.String & "'" & "," & FProg
                End If


            End If
        Next
        Try
            SBO_Application.StatusBar.SetText("Retrieving Data", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            Sqlstr = "SELECT T0.[U_AI_ProgCode], T0.[U_AI_ProgName], T0.[U_AI_PetCode], T0.[U_AI_PetName], T0.[U_AI_Date], T0.[U_AI_TimeStart], T0.[U_AI_TimeEnd], T0.[U_AI_Status] ,T0.[U_AI_Handler] As 'U_AI_Comments',CASE  when T0.[U_AI_ProgCode]='1stTick' then (SELECT  T1.[U_TickCount]  FROM [dbo].[@AI_ATTENDANCE]  T1 WHERE T1.[U_AI_PetCode] =T0.[U_AI_PetCode] and T1.U_AI_Date=T0.U_AI_Date)  when T0.[U_AI_ProgCode]='QTick' then (SELECT  T1.[U_TickCountF]  FROM [dbo].[@AI_ATTENDANCE]  T1 WHERE T1.[U_AI_PetCode] =T0.[U_AI_PetCode] and T1.U_AI_Date=T0.U_AI_Date)  when T0.[U_AI_ProgCode]='2ndTick' then ((SELECT  T1.[U_TickCount2]  FROM [dbo].[@AI_ATTENDANCE]  T1 WHERE T1.[U_AI_PetCode] =T0.[U_AI_PetCode] and T1.U_AI_Date=T0.U_AI_Date)) else (select '' ) end as 'ThickCount' FROM [dbo].[@AI_ACTIVITY]  T0 WHERE T0.[U_AI_ProgCode] in(" & FProg & ") and T0.[U_AI_PetCode] like '" & FPet & "'   and  T0.[U_AI_Date]  between '" & FDt & "'  and '" & TDt & "' ORDER BY T0.[U_AI_Date],T0.[U_AI_PetName],T0.[DocEntry],T0.[U_AI_ProgCode]"
            Dim frm As MY_Report
            frm = New MY_Report
            frm.Act_Report(Sqlstr, Ocompany)
            frm.Text = "Activities Report"
            frm.TopMost = True
            frm.Activate()
            frm.ShowDialog()

        Catch ex As Exception
        End Try

    End Sub
End Class
